<?php


namespace Selibra\Model\Handle;


use Selibra\Tools\Console;
use Selibra\Model\SFModel;

class IncHandle
{


    /**
     * @var SFModel
     */
    private $model;

    public function __construct(SFModel $model)
    {
        $this->model = $model;
    }


    /**
     * @param $field
     * @param int $incNum
     * @return bool|mixed
     */
    public function exec($field, $incNum = 1)
    {
        // 组合
        $where = $this->model->getCondition()->getConditionSql();
        $sql = "UPDATE `{$this->model->getTable()}` SET {$field}={$field}+? WHERE {$where}";
        Console::log($sql);
        $sta = $this->model->prepare($sql);
        if ($sta === false) {
            Console::log($this->model->getError());
            return false;
        }
        return $sta->execute([$incNum]);
    }


}